/**
 * 
 */
package soa.security.domain;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.naming.Name;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

import org.springframework.ldap.odm.annotations.Attribute;
import org.springframework.ldap.odm.annotations.DnAttribute;
import org.springframework.ldap.odm.annotations.Entry;
import org.springframework.ldap.odm.annotations.Id;
import org.springframework.ldap.odm.annotations.Transient;
import org.springframework.ldap.support.LdapNameBuilder;

import soa.security.Constants;

/**
 * @author CreGu
 *
 */
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@Entry(objectClasses = { "zjtzsw-group", "zjtzsw-complex" })
public final class Group extends SoaComplex {

	private static final long serialVersionUID = 4189172177650815995L;

	@XmlTransient
	@Id
	private Name dn;

	@DnAttribute(value = "bid")
	private String bid;

	@Attribute(name = "cname")
	private String name;

	private String ename;

	private String description;

	private int priority;

	private String createTime;

	@XmlTransient
	@Transient
	private String personName;

	public Group() {
	}

	public Group(String bid, String name) {
		super();
		this.bid = bid;
		this.name = name;
	}

	public static Group build(String bid, String name) {
		return new Group(bid, name);
	}

	public Name buildDn(Name baseDn) {
		return LdapNameBuilder.newInstance(baseDn).add(Constants.BID, getBid())
				.build();
	}

	public Name getDn() {
		return dn;
	}

	public void setDn(Name dn) {
		this.dn = dn;
	}

	public String getBid() {
		return bid;
	}

	public void setBid(String bid) {
		this.bid = bid;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getEname() {
		return ename;
	}

	public void setEname(String ename) {
		this.ename = ename;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public int getPriority() {
		return priority;
	}

	public void setPriority(int priority) {
		this.priority = priority;
	}

	public String getCreateTime() {
		return createTime;
	}

	public void setCreateTime(String createTime) {
		this.createTime = createTime;
	}

	public String getPersonName() {
		return personName;
	}

	public void setPersonName(String personName) {
		this.personName = personName;
	}

	@XmlRootElement
	@XmlAccessorType(XmlAccessType.FIELD)
	public static class Groups {
		protected List<Group> group = new ArrayList<Group>();

		public List<Group> getGroup() {
			return this.group;
		}

		public void addGroup(Group group) {
			this.group.add(group);
		}

		public boolean addAll(Collection<? extends Group> c) {
			return group.addAll(c);
		}
	}
}
